<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class ObjectSpace::WeakMap - RDoc Documentation</title>


<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>

<script src="../js/jquery-3.2.0.min.js"></script>

<script src="../js/vue.min.js"></script>
<script src="../js/js.cookie.min.js"></script>

<link href="../css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="../css/rdoc.css" rel="stylesheet">
<link href="../css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
  var index_rel_prefix = "../";
  var darkModeCsseHref = "../css/rdoc-dm.css"
  var defaultModeCssHref = "../css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0-preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="../index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="../table_of_contents.html#pages">Pages</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    

    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link"><a href="../Object.html">Object</a>
</div>

        
<div id="includes-section" class="nav-section">
  <h3>Included Modules</h3>

  <ul class="link-list">
    <li><a class="include" href="../Enumerable.html">Enumerable</a>
  </ul>
</div>

        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-i-5B-5D">#[]</a>
    <li ><a href="#method-i-5B-5D-3D">#[]=</a>
    <li ><a href="#method-i-delete">#delete</a>
    <li ><a href="#method-i-each">#each</a>
    <li ><a href="#method-i-each_key">#each_key</a>
    <li ><a href="#method-i-each_pair">#each_pair</a>
    <li ><a href="#method-i-each_value">#each_value</a>
    <li ><a href="#method-i-include-3F">#include?</a>
    <li ><a href="#method-i-inspect">#inspect</a>
    <li ><a href="#method-i-key-3F">#key?</a>
    <li ><a href="#method-i-keys">#keys</a>
    <li ><a href="#method-i-length">#length</a>
    <li ><a href="#method-i-member-3F">#member?</a>
    <li ><a href="#method-i-size">#size</a>
    <li ><a href="#method-i-values">#values</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-ObjectSpace::WeakMap">
    <h1 id="class-ObjectSpace::WeakMap" class="class">
      class ObjectSpace::WeakMap
    </h1>

    <section class="description">
    
<p>An <a href="WeakMap.html"><code>ObjectSpace::WeakMap</code></a> object holds references to any objects, but those objects can get garbage collected.</p>

<p>This class is mostly used internally by WeakRef, please use <code>lib/weakref.rb</code> for the public interface.</p>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">





                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-5B-5D" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">[]</span><span
                                class="method-args">(p1)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Retrieves a weakly referenced object with the given key</p>

                              <div class="method-source-code" id="5B-5D-source">
            <pre>static VALUE
wmap_aref(VALUE self, VALUE key)
{
    VALUE obj = wmap_lookup(self, key);
    return !UNDEF_P(obj) ? obj : Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-5B-5D-3D" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">[]=</span><span
                                class="method-args">(p1, p2)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Creates a weak reference from the given key to the given value</p>

                              <div class="method-source-code" id="5B-5D-3D-source">
            <pre>static VALUE
wmap_aset(VALUE self, VALUE key, VALUE val)
{
    struct weakmap *w;
    TypedData_Get_Struct(self, struct weakmap, &amp;weakmap_type, w);

    VALUE pair[2] = { key, val };

    st_update(w-&gt;table, (st_data_t)pair, wmap_aset_replace, (st_data_t)pair);

    RB_OBJ_WRITTEN(self, Qundef, key);
    RB_OBJ_WRITTEN(self, Qundef, val);

    return nonspecial_obj_id(val);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-delete" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">delete</span><span
                                class="method-args">(p1)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Delete the given key from the map</p>

                              <div class="method-source-code" id="delete-source">
            <pre>static VALUE
wmap_delete(VALUE self, VALUE key)
{
    struct weakmap *w;
    TypedData_Get_Struct(self, struct weakmap, &amp;weakmap_type, w);

    VALUE orig_key = key;
    st_data_t orig_key_data = (st_data_t)&amp;orig_key;
    st_data_t orig_val_data;
    if (st_delete(w-&gt;table, &amp;orig_key_data, &amp;orig_val_data)) {
        VALUE orig_val = *(VALUE *)orig_val_data;

        rb_gc_remove_weak(self, (VALUE *)orig_key_data);
        rb_gc_remove_weak(self, (VALUE *)orig_val_data);

        wmap_free_entry((VALUE *)orig_key_data, (VALUE *)orig_val_data);

        if (wmap_live_p(orig_val)) {
            return orig_val;
        }
    }

    if (rb_block_given_p()) {
        return rb_yield(key);
    }
    else {
        return Qnil;
    }
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-each" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">each</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Iterates over keys and objects in a weakly referenced object</p>

                              <div class="method-source-code" id="each-source">
            <pre>static VALUE
wmap_each(VALUE self)
{
    struct weakmap *w;
    TypedData_Get_Struct(self, struct weakmap, &amp;weakmap_type, w);

    wmap_foreach(w, wmap_each_i, (st_data_t)0);

    return self;
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="WeakMap.html#method-i-each_pair">each_pair</a>
                            </div>

                          </div>

                  <div id="method-i-each_key" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">each_key</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Iterates over keys and objects in a weakly referenced object</p>

                              <div class="method-source-code" id="each_key-source">
            <pre>static VALUE
wmap_each_key(VALUE self)
{
    struct weakmap *w;
    TypedData_Get_Struct(self, struct weakmap, &amp;weakmap_type, w);

    wmap_foreach(w, wmap_each_key_i, (st_data_t)0);

    return self;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-each_pair" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">each_pair</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              <p>Iterates over keys and objects in a weakly referenced object</p>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="WeakMap.html#method-i-each">each</a>
                            </div>
                          </div>

                  <div id="method-i-each_value" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">each_value</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Iterates over keys and objects in a weakly referenced object</p>

                              <div class="method-source-code" id="each_value-source">
            <pre>static VALUE
wmap_each_value(VALUE self)
{
    struct weakmap *w;
    TypedData_Get_Struct(self, struct weakmap, &amp;weakmap_type, w);

    wmap_foreach(w, wmap_each_value_i, (st_data_t)0);

    return self;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-include-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">include?</span><span
                                class="method-args">(p1)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if <code>key</code> is registered</p>

                              <div class="method-source-code" id="include-3F-source">
            <pre>static VALUE
wmap_has_key(VALUE self, VALUE key)
{
    return RBOOL(!UNDEF_P(wmap_lookup(self, key)));
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="WeakMap.html#method-i-member-3F">member?</a>, <a href="WeakMap.html#method-i-key-3F">key?</a>
                            </div>

                          </div>

                  <div id="method-i-inspect" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">inspect</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="inspect-source">
            <pre>static VALUE
wmap_inspect(VALUE self)
{
    VALUE c = rb_class_name(CLASS_OF(self));
    struct weakmap *w;
    TypedData_Get_Struct(self, struct weakmap, &amp;weakmap_type, w);

    VALUE str = rb_sprintf(&quot;-&lt;%&quot;PRIsVALUE&quot;:%p&quot;, c, (void *)self);

    wmap_foreach(w, wmap_inspect_i, (st_data_t)str);

    RSTRING_PTR(str)[0] = &#39;#&#39;;
    rb_str_cat2(str, &quot;&gt;&quot;);

    return str;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-key-3F" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">key?</span><span
                                class="method-args">(p1)</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if <code>key</code> is registered</p>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="WeakMap.html#method-i-include-3F">include?</a>
                            </div>
                          </div>

                  <div id="method-i-keys" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">keys</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Iterates over keys and objects in a weakly referenced object</p>

                              <div class="method-source-code" id="keys-source">
            <pre>static VALUE
wmap_keys(VALUE self)
{
    struct weakmap *w;
    TypedData_Get_Struct(self, struct weakmap, &amp;weakmap_type, w);

    VALUE ary = rb_ary_new();
    wmap_foreach(w, wmap_keys_i, (st_data_t)ary);

    return ary;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-length" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">length</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the number of referenced objects</p>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="WeakMap.html#method-i-size">size</a>
                            </div>
                          </div>

                  <div id="method-i-member-3F" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">member?</span><span
                                class="method-args">(p1)</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if <code>key</code> is registered</p>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="WeakMap.html#method-i-include-3F">include?</a>
                            </div>
                          </div>

                  <div id="method-i-size" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">size</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the number of referenced objects</p>

                              <div class="method-source-code" id="size-source">
            <pre>static VALUE
wmap_size(VALUE self)
{
    struct weakmap *w;
    TypedData_Get_Struct(self, struct weakmap, &amp;weakmap_type, w);

    st_index_t n = st_table_size(w-&gt;table);

#if SIZEOF_ST_INDEX_T &lt;= SIZEOF_LONG
    return ULONG2NUM(n);
#else
    return ULL2NUM(n);
#endif
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="WeakMap.html#method-i-length">length</a>
                            </div>

                          </div>

                  <div id="method-i-values" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">values</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Iterates over values and objects in a weakly referenced object</p>

                              <div class="method-source-code" id="values-source">
            <pre>static VALUE
wmap_values(VALUE self)
{
    struct weakmap *w;
    TypedData_Get_Struct(self, struct weakmap, &amp;weakmap_type, w);

    VALUE ary = rb_ary_new();
    wmap_foreach(w, wmap_values_i, (st_data_t)ary);

    return ary;
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>.</p><p><a href="https://jamesbritt.bandcamp.com/">Maximum R+D</a>.  </p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

